package com.skycity.framework.uaa.pojo.entity;

import cn.skycity.framework.core.base.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import cn.skycity.framework.core.constants.UserConstants;

/**
 * @author haoxr
 * @date 2020-11-06
 */
@Data
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@TableName("sys_menu")
public class SysMenu extends BaseEntity {

    private String menuName;
    private Long parentId;
    private Integer sort;
    //路由路径
    private String path;
    private String component;
    //0: 目录 1：菜单；2：按钮
    private String menuType;
    private String visible;
    private String status;

    private String perms;
    private String icon;

    private String remark;



    /**
     * 获取路由地址
     */
    public String getRouterPath() {
        String routerPath = this.path;
        // 内链打开外网方式
        // 非外链并且是一级目录（类型为目录）
        if (0L == getParentId() && "0".equals(getMenuType())) {
            routerPath = "/" + this.path;
        }
        return routerPath;
    }


    /**
     * 获取组件信息
     */
    public String getComponentInfo() {
        String component = UserConstants.LAYOUT;
        if (StringUtils.isNotEmpty(this.component) && !isMenuFrame()) {
            component = this.component;
//        } else if (StringUtils.isEmpty(this.component) && getParentId() != 0L && isInnerLink()) {
//            component = UserConstants.INNER_LINK;
        } else if (StringUtils.isEmpty(this.component) && isParentView()) {
            component = UserConstants.PARENT_VIEW;
        }
        return component;
    }

    /**
     * 是否为菜单内部跳转
     */
    public boolean isMenuFrame() {
        return getParentId() == 0L && UserConstants.TYPE_MENU.equals(menuType);// && isFrame.equals(UserConstants.NO_FRAME);
    }

    /**
     * 是否为parent_view组件
     */
    public boolean isParentView() {
        return getParentId() != 0L && UserConstants.TYPE_DIR.equals(menuType);
    }

}
